package com.googlecode.dgwt.client.dojox.data.model.base;

import com.googlecode.dgwt.client.dojo.Dojo;
import com.googlecode.dgwt.client.dojo.data.model.StoreColumnBase;
import com.googlecode.dgwt.client.dojo.exception.ValidationException;


/**
 * @author      Wellington Tadeu dos Santos
 * @since       DGWT v0.01
 */
public abstract class NamedColumnBase<Item, Type> extends StoreColumnBase<Item, Type> implements NamedColumn<Item, Type> {

    private String name;
    
    public NamedColumnBase() {
        name = "";
    }
    
    public NamedColumnBase(String name) {
        setName(name);
    }
    
    public void setName(String name) {
        if (name == null) {
            name = "";
        }
        if (!name.equals(this.name)) {
            this.name = name;
            onColumnChanged();
        }
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setDisplayValue(Item item, String value) throws ValidationException {
        try {
            super.setDisplayValue(item, value);
        } catch (ValidationException e) {
            throw new ValidationException(Dojo.string.propertiesSubstitute(e.getMessage(), 
                                          Dojo.string.toProperCase(getName())));
        }
    }

}
